<template>
  <div>
    <div>
      <el-button @click="addFun">点击</el-button>
    </div>
    <el-radio-group v-model="CancellationRadioValue">
      <div v-for="(item, index) in Cancellation" :key="index">
        <el-radio :label="item.radioValue"></el-radio>
        <el-input 
          v-model="item.value" 
          placeholder="预警值" 
          @input="handleInput(index, item.value)">
        </el-input>
      </div>
    </el-radio-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      CancellationRadioValue: undefined,
      Cancellation: [],
    };
  },
  methods: {
    addFun() {
      this.Cancellation.push({
        name: "取消率：≥",
        type: "1",
        value: undefined,
        radioValue: ""
      });
    },
    handleInput(index, newValue) {
      console.log("index",index);
      console.log("newValue",newValue);
      this.Cancellation[index].value = newValue;



      

      // 如果当前输入框被选中，更新 CancellationRadioValue 和 radioValue
      if (this.CancellationRadioValue === this.Cancellation[index].radioValue) {
        this.CancellationRadioValue = newValue;
        this.Cancellation[index].radioValue = newValue;
      } else {
        this.Cancellation[index].radioValue = newValue;
      }
    }
  },
};
</script>